<?php
include_once "Filter.class.php";
class indexFilter extends Filter{
	
	protected $_openRS = array(
			'Index' => array('Test'),
			'Account' => array('Login','Mobileregister','Getverifycode','Checkverifycode','Resetpassword','getNewVersion'),
			'Exercise'=> array('Searchvideolist', 'Getnotevaluelist', 'Getcommentlist'),
			'Ocr' => array('Recognize','Getresultlist',"Postnotexist"),
			'Persondetail' => array('Upimage','Getsubjectlist'),
			'Questionexplain' => array('Getquestiontitle','Getquestionanswer','Getskill','Getknowledge','Getqusetionskilllist'),
			'Setting' => array('Help')
	); //允许不用登陆访问的资源
	
	//属于账号的资源
	protected $_selfRS = array(	'Account' => array('Index','Login','Logout','Changepw','Myinfo'),
								'Index'	=>	array('Index','Main','Menu','Header') );
	
	//最终的资源列表
	protected $_RSList = array();
	
	public function doFilter(){
		
		$session = $this->getApp()->loadUtilClass("SessionUtil");
		
		if($userid = $session->get("session_userid") ){
		//if($userid=1){//测试用
			//print_r($_SESSION);
			//$user=new uuser();
			//print_r($_COOKIE);
			//echo $userid."<br/>";
			//$userdata=$user->getAdminFromAdminid($userid);
			//print_r($userdata);
			//exit();
			//$this->getApp()->getView()->setStatus("0");
				
			//if($userdata){
// 				$this->getApp()->getView()->setStatus("1");
				//设置用户的信息
				//$this->getApp()->putData('userinfo', $userdata );
				
				
				//$this->_RSList = array_merge( $this->_RSList,$this->_selfRS );
				
// 				$role = new role();
// 				if( $resList = $role->getResourceOfRole($userdata["role_id"]) ){
// 					foreach ($resList as $res){
// 						$this->_RSList[ $res["ctrl_class"] ] = array();	
// 						$ctrl_id = $res["ctrl_id"];
// 						if($action_list = $role->getActionList($ctrl_id)){
// 							foreach ($action_list as $al){
// 								$this->_RSList[ $res["ctrl_class"] ][] = $al["action_function"];
// 							}
// 						}
// 					}
// 				}
				
				
// 				if($this->canViste($this->getCName(), $this->getAName())){
// 					$this->getApp()->putData('resource', $this->_RSList );
// 				}else{
// 					echo "access deny!";
// 					exit();
// 				}
				
				
	
//			}else{
				//$session->clear();
				//$view = $this->getApp()->getView();
				//$view->setState("0");
				//$view->setMsg("error:invalid session infomation!");
				//$view->setStatus("0");
				//$view->display("json");
// 				echo "session error, access deny!";
			//	exit();
//			}
		}else{
			//$view = $this->getApp()->getView();
// 			//echo $this->getCName().$this->getAName();
			//if( $this->canViste( $this->getCName(), $this->getAName() ) ){
				//$this->getApp()->gotoUrl("Account","login");
				//echo "no login but can access!<br/>";
			//	$view->setStatus("0");
			//}else{
			//	$view->setState("0");
			//	$view->setMsg("错误:请登录!");
			//	$view->setStatus("0");
			//	$view->display("json");
			//	exit();
// 				$this->getApp()->gotoUrl("Account","login","4");
// 				exit("no login access deny!");
			
			//}
		}
	
	}
	
	//检查是否可以访问
	public function canViste($cName,$aName){
		//if( $this->isOpenRS($cName, $aName) ){
			return true;
		//}else{
		//	return array_key_exists($cName,$this->_RSList) ? in_array( $aName, $this->_RSList[$cName]  ) : false;
		//}
	}
	
	public function isOpenRS($cName,$aName){
		//return  array_key_exists($cName, $this->_openRS) ? in_array($aName, $this->_openRS[$cName]) :false ;
	}

}

?>